package com.cy.cykh.app.http

import io.reactivex.Observable
import okhttp3.OkHttpClient
import okhttp3.ResponseBody
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path

/**
 * @author Administrator
 * @FileName
 * @date 2019/1/2 9:23
 */
interface CdyApi {

    @GET("api/day/{date}")
    fun getDataByDate(@Path("date") date: String): Observable<ResponseBody>

    @GET("history")
    fun getHistory(): Observable<ResponseBody>

    companion object CdyFactory{
        fun create():CdyApi {

            val logging = HttpLoggingInterceptor()
            logging.level = HttpLoggingInterceptor.Level.BASIC
            val client = OkHttpClient.Builder()
                    .addInterceptor(logging)
                    .build()

            val retrofit = Retrofit.Builder()
                    .client(client)
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .baseUrl("http://gank.io/")
                    .build()
            return retrofit.create(CdyApi::class.java)
        }
    }
}